package huoye.shops.huoye.operation.adapter;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.codeideology.android.widget.recycler.RecyclerViewAdapter;

import butterknife.BindView;
import huoye.shops.R;
import huoye.shops.huoye.operation.model.ManageEventData;
import huoye.shops.widget.RoundImageView;


/**
 * Created by uesr on 2018/8/10.
 */

public class ManageEventAdapter extends RecyclerViewAdapter<ManageEventAdapter.ViewHolder,ManageEventData> {





    public ManageEventAdapter(Context context) {
        super(context, R.layout.item_manage_event);
    }

    @Override
    protected ViewHolder initViewHolder(View view, int i) {

        return new ViewHolder(view);
    }

    @Override
    protected void bindView(ViewHolder holder, final ManageEventData manageEventData, int i) {
        holder.tvEventName.setText(manageEventData.getEtClassName());


        if(manageEventData.getiState() == 1 || manageEventData.getiState() == 0 ){
            holder.tvEventStare.setSelected(false);
            holder.tvEventStare.setText("活动进行中");
            if(manageEventData.isJoin() || manageEventData.isNaming()){
                holder.btnJoin.setText("详情");
            }else {
                holder.btnJoin.setText("参加");
            }
        }else {
            holder.tvEventStare.setSelected(true);
            holder.tvEventStare.setText("已结束");
            holder.btnJoin.setText("详情");
        }



        if(manageEventData.getCreateType() == 0){
            holder.rvHead.setVisibility(View.VISIBLE);
            if(manageEventData.getEtClassCode().equals("gxjc")){
               holder.rvHead.setImageResource(R.mipmap.ic_event_gxjc);
            }else {
                holder.rvHead.setImageResource(R.mipmap.ic_event_qmccl);
            }
        }else{
            //测试数据
            holder.rvHead.setVisibility(View.GONE);
            holder.tvEventName.setText("我创建的活动");
            holder.btnJoin.setText("详情");
        }

        holder.tvEventTime.setText("活动期限"+manageEventData.getEndTime());


        holder.btnJoin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(manageEventData.getCreateType() == 0){
                    if(manageEventData.getiState() == 1 || manageEventData.getiState() == 0 ){
                        //进行判断是参加还是详情
                        if(manageEventData.isJoin() || manageEventData.isNaming()){
                            listener.onDetailsClick(manageEventData);
                        }else {
                            listener.onJoinClick(manageEventData);
                        }
                    }else {
                        listener.onDetailsClick(manageEventData);
                    }

                }else{
                   listener.onBuildClick(manageEventData);
                }


            }
        });



        holder.tvEventExplain.setText(manageEventData.getRemarks());

    }


    public class ViewHolder extends RecyclerViewAdapter.ViewHolder {
        @BindView(R.id.item_manage_event_rv)
        RoundImageView rvHead ;


        @BindView(R.id.item_manage_event_tv_event_name)
        TextView tvEventName;

        @BindView(R.id.item_manage_event_tv_event_state)
        TextView tvEventStare;

        @BindView(R.id.item_manage_event_tv_event_explain)
        TextView tvEventExplain;

        @BindView(R.id.item_manage_event_tv_event_time)
        TextView tvEventTime;



        @BindView(R.id.item_manage_event_btn_join)
        Button btnJoin ;
  ;


        public ViewHolder(View itemView) {
            super(itemView);
        }
    }



    public void setOnManageEventDataListener(OnManageEventDataListener onManageEventDataListener) {
        this.listener = onManageEventDataListener;
    }

    private OnManageEventDataListener listener;

    public interface OnManageEventDataListener {

        void onJoinClick(ManageEventData ManageEventData);
        void onDetailsClick(ManageEventData ManageEventData);
        void onBuildClick(ManageEventData ManageEventData);


    }

}
